package com.leyou.item.service.impl;

import com.leyou.item.mapper.SpecGroupMapper;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import com.leyou.item.service.SpecGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SpecGroupServiceImpl implements SpecGroupService {

    @Autowired
    private SpecGroupMapper mapper;
    @Autowired
    private SpecParamMapper specParamMapper;

    @Override
    public List<SpecGroup> queryGroupByCid(Long cid) {
        SpecGroup group=new SpecGroup();
        group.setCid(cid);
        return this.mapper.select(group);
    }

    /*
    删除参数组以及参数组的规格参数
     */
    @Transactional
    @Override
    public int deleteGroupById(Long gid) {
        this.mapper.deleteByPrimaryKey(gid);
        SpecParam param=new SpecParam();
        param.setGroupId(gid);
        specParamMapper.delete(param);
        return 0;
    }

    @Override
    public int saveGroup(SpecGroup group) {
        this.mapper.insertSelective(group);
        return 0;
    }

    @Override
    public int update(SpecGroup group) {
        this.mapper.updateByPrimaryKey(group);
        return 0;
    }
}
